//
//  UIImageView+TXWebImage.m
//  COO
//
//  Created by YM on 2017/5/5.
//  Copyright © 2017年 Tincent. All rights reserved.
//

#import "UIImageView+TXWebImage.h"

#if __has_include(<YYKit/YYKit.h>)
#import <YYKit/YYKit.h>
#else
#import "YYKit.h"
#endif

@implementation UIImageView (TXWebImage)

- (void)tx_setImageWithURL:(NSURL *)imageURL
          placeholderImage:(UIImage *)placeholder {

    [self setImageWithURL:imageURL
              placeholder:placeholder
                  options:YYWebImageOptionProgressiveBlur | YYWebImageOptionSetImageWithFadeAnimation
               completion:nil];
}

- (void)tx_setImageWithURL:(NSURL *)imageURL
          placeholderImage:(UIImage *)placeholder
                 completed:(void (^)(UIImage * image_, NSURL * url_, UIImageView *imageView_))completed {
    
    TX_WS(weakSelf);
    
    [self setImageWithURL:imageURL
              placeholder:placeholder
                  options:YYWebImageOptionProgressiveBlur | YYWebImageOptionSetImageWithFadeAnimation
               completion:^(UIImage * _Nullable image, NSURL * _Nonnull url, YYWebImageFromType from, YYWebImageStage stage, NSError * _Nullable error) {

                   if (error) {
                       if (completed) {
                           completed(nil, url, weakSelf);
                       }
                   }
                   else {
                       if (completed) {
                           completed(image, url, weakSelf);
                       }
                   }
               }];
}

@end
